package com.imodia.checkoo.thread.htmlInfo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.hsq.commons.util.file.FileUtil;
import com.imodia.checkoo.bean.CmsPageBean;
import com.imodia.checkoo.service.CmsPageService;

public class PageTaskExecutorHtml extends TaskExecutorHtml{
	
	private static final Log log = LogFactory.getLog(PageTaskExecutorHtml.class);
	
	private CmsPageService cmsPageService;
	
	public void setCmsPageService(CmsPageService cmsPageService) {
		this.cmsPageService = cmsPageService;
	}
	
	public void htmlByPageId(int pageId) {	
		log.debug("______htmlByPageId start_____________");
		if(!checkData()){
			return;
		}
		CmsPageBean pageInfo = cmsPageService.get(pageId);
		html4page(pageInfo);
	}

	public void htmlIndex() {
		if(!checkData()){
			return;
		}
		taskExecutor.execute(new ThreadTaskExecutorHtml(siteUrl+"index.do?isHtml=1",realPath+"/index.html"));
	}
	
	public void html4page(CmsPageBean pageInfo){
		log.info(")))"+pageInfo.getIsValidate());
		if(pageInfo.getIsValidate()==1){
			taskExecutor.execute(new ThreadTaskExecutorHtml(siteUrl+"/"+pageInfo.getDynamicUrl()+"&isHtml=1",realPath+"/"+pageInfo.getHtmlUrl()));
		}else{
			FileUtil.delete(realPath+pageInfo.getHtmlUrl());
		}
	}
	
	
	

}
